extends Reference

class_name Player

var uid='0'
var uName=''
var actor=null
var isActive=false #激活,有actor就是激活

var djState=0 # 0 不是dj  1正在当dj
var djPower=600.0 #当dj时，会减  600.0
var lastDjTime=0
var lastDjPower=600.0
var maxDjPower=600.0  #600
var reduceDJPowerSpeed=2
var gainDJPowerSpeed=1
func isDjOk():
	return OS.get_system_time_secs()>=lastDjTime+(maxDjPower-lastDjPower)/gainDJPowerSpeed
func startDJ():
	djState=1
	djPower=(OS.get_system_time_secs()-lastDjTime)*gainDJPowerSpeed+lastDjPower
	djPower=min(djPower,maxDjPower)
	if actor:
		actor.startDJ()
	
func stopDJ():
	djState=0
	lastDjPower=djPower
	lastDjPower=max(lastDjPower,0)
	lastDjTime=OS.get_system_time_secs()
	if actor:
		actor.stopDJ()

func _addActor():
	var main=G.main as Main
	actor=load('res://prefabs/Actor.tscn').instance() as Actor
	main.actorPlace.add_child(actor)
	actor.setName(uName)
	actor.randomSkin()
	actor.setRandomPos()
	actor.player=self
	#随机游走
	actor.randomNormalState()

var removeTimer=0 
func active():
	removeTimer=0
	if isActive:
		return
	isActive=true
	_addActor()
func unActive():
	isActive=false
	if actor:
		actor.queue_free()
		actor=null
